package com.gitee.l0km.beanfilter.core;

/**
 * 过滤器适用编码解码阶段定义
 * @author guyadong
 *
 */
public enum CodecPhase {
	/** 无 */NONE(false,false),
	/** 序列化/反序列化阶段 */BOTH(true,true),
	/** 序列化阶段 */SERIALIZATION(true,false),
	/** 反序列化阶段 */DESERIALIZATION(false,true);
	/** 是否用于序列化阶段 */
	public final boolean serialization;
	/** 是否用于反序列化阶段 */
	public final boolean deserialization;
	private CodecPhase(boolean serialization, boolean deserialization) {
		this.serialization = serialization;
		this.deserialization = deserialization;
	}
	public boolean singlePhase() {
		return (serialization && !deserialization) || (!serialization && deserialization);
	}
	public boolean match(CodecPhase target) {
		if(null == target) {
			return false;
		}
		if(serialization && !target.serialization) {
			return false;
		}
		if(deserialization && !target.deserialization) {
			return false;
		}
		return true;
	}
}
